var express = require('express');
var request = require('request');

const PROXY_HOST = 'http://localhost:8080';
const PROXY_RESOURCES = [
    '/',
    '/index.js',
    '/index.html',
    '/style.css',
    '/webpack-dev-server/',
    '/__webpack_dev_server__/live.bundle.js'
];

const REG = new RegExp('^('+PROXY_RESOURCES.join('|')+')$|^/sockjs-node');

module.exports = function(req, res,next) {
    var url = req.url;
    if(REG.test(url)) {
        console.log(url);
        var proxyUrl = PROXY_HOST + url;
        req.pipe(request(proxyUrl)).pipe(res);
    } else {
        next();
    }
};


